package com.eternal.data.ui;

import android.content.Context;
import androidx.annotation.Nullable;
import android.util.AttributeSet;

import com.eternal.base.concat.TmpHum;
import com.eternal.base.global.BluetoothKey;

import java.math.RoundingMode;
import java.text.DecimalFormat;

public class GraphHumView extends GraphView{
    private DecimalFormat format;

    public GraphHumView(Context context) {
        this(context, null);
    }

    public GraphHumView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GraphHumView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        format=new DecimalFormat("#.0");
        format.setRoundingMode(RoundingMode.FLOOR);
    }

    @Override
    TimeValue getItem(int position) {
        TmpHum temp=adapter.getItem(position);
        return new TimeValue(temp.time, temp.hum);
    }

    @Override
    int getAvg() {
        return adapter.avgHum;
    }

    @Override
    int getMax() {
        return adapter.aMaxHum;
    }

    @Override
    int getMin() {
        return adapter.aMinHum;
    }

    @Override
    String formatValue(int value) {
        if(value== BluetoothKey.EMPTY){
            return "--%";
        }
        return format.format(value/100f)+"%";
    }
}
